package com.example.xiaodu.yuejian12.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaodu.yuejian12.Bean.ActivityBean;
import com.example.xiaodu.yuejian12.Bean.MasterBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

public class MasterDetailActivity extends AppCompatActivity {

    private TextView masterName,masterIntro,masterPhone;
    private ImageView imageView;
    private UserModel userModel;
    private RetrofitListener<MasterBean> listener;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_master_detail);

        initView();
        initListener();
        getData();
    }

    public void initView(){
        imageView=(ImageView)findViewById(R.id.master_picture);
        masterName=(TextView)findViewById(R.id.name);
        masterPhone=(TextView)findViewById(R.id.phone);
        masterIntro=(TextView)findViewById(R.id.intro);

    }

    public void initListener(){
        listener=new RetrofitListener<MasterBean>() {
            @Override
            public void onSuccess(MasterBean masterBean) {
                masterName.setText(masterBean.getMname());
                masterPhone.setText(masterBean.getMphone());
                masterIntro.setText(masterBean.getMintro());
                Picasso.with(imageView.getContext()).load("http://10.0.2.2/yuejian/public/static/master/"+masterBean.getMpic()).into(imageView);

            }

            @Override
            public void onFail(String msg) {

            }
        };
    }

    public void getData(){
        userModel=new UserModel();
        userModel.getMasterDetail(getIntent().getIntExtra("masterID",1),listener);
    }
}
